package com.github.MrWub;

import java.io.File;
import java.io.IOException;

import org.bukkit.plugin.java.JavaPlugin;

import com.github.MrWub.key.KeyManager;
import com.github.MrWub.key.KeyPressCatcher;
import com.github.MrWub.utils.YamlConfig;

public class SWskillAPI extends JavaPlugin{
	private YamlConfig c = null;
	@Override
	public void onEnable() {
		getLogger().info("SWSkill已经启用. 作者: 914554688wyt & SC-K");
		loadUniConfig();
		new KeyManager(this);
		KeyManager.loadALLKeyOption();
		new KeyPressCatcher(this);
	}
	
	@Override
	public void onDisable() {
		KeyManager.saveALLKeyOption();
	}
	
	private void loadUniConfig() {
		saveDefaultConfig();
		File configFile = new File(getDataFolder(), "config.yml");
		try {
			c = new YamlConfig();
			c.load(configFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 返回SWskillAPI本身的config文件. (即KeyOption配置)
	 * @return
	 */
	public YamlConfig getC() {
		return c;
	}
	
	/**
	 * 获得一个支持键中文的yaml实例.
	 * @return YamlConfig实例
	 */
	public YamlConfig getUnicodeConfig(File file) {
		YamlConfig ret = null;
		try {
			ret = new YamlConfig();
			ret.load(file);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}
}
